from selenium import webdriver
from selenium.webdriver.common.by import By

from utils import WebUtilDriver
from base.base_page import BasePage

# class 对象库层():
class LoginPage(BasePage):
    def __init__(self):
        super().__init__()  # 调用父类的init方法


    def find_username(self):
        '''
        当前方法查找的是用户名填充位置
        :return: 元素返回
        '''
        username_element = self.get_element(By.ID,'username')
        return username_element

    def find_password(self):
        '''
        当前方法查找的是密码
        :return:
        '''
        password_element = self.get_element(By.XPATH,'//*[@id="password"]')
        return password_element

    def find_verify(self):
        '''
        当前方法查找的是验证码
        :return:
        '''
        verify_element = self.get_element(By.XPATH, '//*[@id="verify_code"]')
        return verify_element
    def find_submit(self):
        '''
        当前方法查找的是登录按钮
        :return:
        '''
        submit_element = self.get_element(By.XPATH,'//*[@id="loginform"]/div/div[6]/a')
        return submit_element

    def find_re_verify(self):
        '''
        当前方法查找的是刷新验证码按钮
        :return:
        '''
        re_verify_element = self.get_element(By.ID,'verify_code_img')
        return re_verify_element

    def find_forget_pwd(self):
        '''
        当前方法,查找的是忘记密码按钮
        :return:
        '''
        foget_pwd_element = self.get_element(By.XPATH,'//div[@class="foget_pwt"]/a')
        return foget_pwd_element




# 操作层
class LoginHandler():

    def __init__(self):
        self.login_page = LoginPage()

    # 填充用户名
    def fill_username(self,username):
        self.login_page.find_username().send_keys(username)

    # 填充密码
    def fill_pwd(self,pwd):
        self.login_page.find_password().send_keys(pwd)

    # 填充验证码
    def fill_verify(self,verify):
        self.login_page.find_verify().send_keys(verify)

    # 点击登录
    def click_login(self):
        self.login_page.find_submit().click()


    # 点击忘记密码
    def click_foget(self):
        self.login_page.find_forget_pwd().click()



# 业务层
class LoginAct():

    def  __init__(self):
        self.handler_login = LoginHandler()

    def login_common(self,username,pwd,verify):

        # 输入用户名
        self.handler_login.fill_username(username)

        # 输入密码
        self.handler_login.fill_pwd(pwd)

        # 输入验证码
        self.handler_login.fill_verify(verify)

        # 点击登录
        self.handler_login.click_login()
        pass

    def foget_pwd(self):
        # 点击忘记密码
        self.handler_login.click_foget()

    def login_ali(self):
        pass

    def login_wechat(self):
        pass

    def login_qq(self):
        pass

    def refer_register(self):
        pass